package com.mtw.bbs.reply.service;


import com.mtw.bbs.article.pojo.vo.ReplyCountVo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 *
 */
@Service
@RequiredArgsConstructor
public class ReplyProviderService {


    private final ReplySubjectService subjectService;


    /**
     * 根据用业务id和实体id获取评论数量
     * @param objectType    业务id
     * @param objectId      实体id
     */
    public ReplyCountVo getCountByBusAndMessageId(String objectType, String objectId){

        Integer relyCount = subjectService.getRelyCount(objectType, objectId);
        ReplyCountVo vo = new ReplyCountVo();
        vo.setObjectId(objectId);
        vo.setCount(relyCount==null?0:relyCount);
        return vo;

    }


    /**
     * 根据用业务id和实体id集合获取评论数量
     */
    public List<ReplyCountVo>getCountByBusAndMessageIds(String objectType,List<String> objectIds){

        Map<String, Integer> replyCountList = subjectService.getRelyCountByIds(objectType, objectIds);
        List<ReplyCountVo> result = new ArrayList<>(replyCountList.size());
        replyCountList.forEach((k,v)->{
            ReplyCountVo vo = new ReplyCountVo();
            vo.setObjectId(k);
            vo.setCount(v==null?0:v);
            result.add(vo);
        });
        return result;
    }



}
